﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;

namespace AppSocketData
{
    public interface ISqlCommand
    {
        IEnumerable<T> Query<T>(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        Task<IEnumerable<T>> QueryAsync<T>(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        T QueryEntity<T>(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        Task<T> QueryEntityAsync<T>(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        Tuple<IEnumerable<T1>, T2> QueryMultiple<T1, T2>(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        Task<SqlMapper.GridReader> QueryMultipleAsync(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        Task<(IEnumerable<T1>, T2)> QueryMultipleAsync<T1, T2>(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        int Execute(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        Task<int> ExecuteAsync(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        Task<int> ExecuteMultipleAsync<T>(string sqlTextOrScriptName, CommandType commandType, List<T> parameters);

        T ExecuteScalar<T>(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        object ExecuteScalar(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        Task<object> ExecuteScalarAsync(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);
        Task<T> ExecuteScalarAsync<T>(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        object ExecuteReader(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        Task<object> ExecuteReaderAsync(string sqlTextOrScriptName, CommandType commandType, DynamicParameters parameters = null);

        /// <summary>
        /// 获取Insert操作语句（使用参数方式）
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="fieldName">其他待新增字段</param>
        /// <returns></returns>
        string GetInsertSql(string tableName, string[] fieldName);

        /// <summary>
        /// 获取Update操作语句（使用参数方式）
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="modifyFields">待修改字段</param>
        /// <param name="conditionFields">条件字段（仅 and 拼接多个条件字段）</param>
        /// <returns></returns>
        string GetUpdateSql(string tableName, string[] modifyFields, string[] conditionFields);

        /// <summary>
        /// 根据某些特定条件获取查询语句
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="fieldNames">>返回所需字段</param>
        /// <param name="conditionFields">条件字段（连接符and、比较符等于）</param>
        /// <returns></returns>
        string GetQuerySql(string tableName, string[] fieldNames, string[] conditionFields, string orderByfieldName, bool? ascending = null);

        /// <summary>
        /// 事务执行--异步
        /// </summary>
        /// <param name="sqls">sql列表</param>
        /// <param name="parameters">参数列表</param>
        /// <returns></returns>
        Task<int> TransactionExecuteAsync(List<string> sqls, List<DynamicParameters> parameters);

        Task<int> TransactionExecuteMultipleAsync<T>(List<string> sqls, List<DynamicParameters> parameters, string sql2,
            List<T> parameterList);

    }
}
